package com.cat.twoPointerTechnique;
/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-length-of-string-after-deleting-similar-ends/description/
 * @create 2025/8/2 18:14
 * @since JDK17
 */

public class Solution08 {
    public int minimumLength(String str) {
        char[] s = str.toCharArray();
        int n = s.length, i, j;
        for (i = 0, j = n - 1; i < j; ) {
            if (s[i] != s[j]) {
                return j - i + 1;
            }
            char t = s[i];
            while (i <= j && s[i] == t) {     //
                i++;
            }
            while (i <= j && s[j] == t) {
                j--;
            }
        }
        return i > j ? 0 : 1;
    }
}

